/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package simplemetrosystem.view.table;

import java.awt.GridBagLayout;
import javax.swing.JButton;
import javax.swing.JPanel;
import simplemetrosystem.view.Layout.GBC;
import simplemetrosystem.view.InformationPane;
import simplemetrosystem.model.Element.MetroStation;
import simplemetrosystem.model.charlanguage.NameMap;
import simplemetrosystem.view.action.NewStationActionListener;
import simplemetrosystem.view.action.RemoveStationActionListener;

/**
 *
 * @author Eric Qian
 */
public class AllStationTableToolPane extends JPanel {

    /**
     * 
     * @param infPane
     */
    public AllStationTableToolPane(InformationPane infPane) {
        this.infPane = infPane;
        nameMap = NameMap.getInstance();
        loadComponent();
    }

    private void loadComponent() {
        setLayout(new GridBagLayout());

        add(getAddStationButton(), new GBC(0, 0).setWeight(0, 0).setInsets(0, 2, 0, 2));
        add(getRemoveStationButton(), new GBC(1, 0).setWeight(0, 0).setInsets(0, 2, 0, 2));
        add(getSearchPane(), new GBC(2, 0).setWeight(100, 0).setFill(GBC.BOTH));
    }

    private JButton getAddStationButton() {
        if (addStationButton == null) {
            addStationButton = new JButton();
            addStationButton.setText(nameMap.getName("New Station"));
            addStationButton.setToolTipText(nameMap.getName("New Station"));
            addStationButton.addActionListener(new NewStationActionListener(infPane.getFrame()));
        }
        return addStationButton;
    }

    private JButton getRemoveStationButton() {
        if (removeStationButton == null) {
            removeStationButton = new JButton();
            removeStationButton.setText(nameMap.getName("Remove Station"));
            removeStationButton.setToolTipText("Remove Station");
            removeStationListener = new RemoveStationActionListener(infPane.getFrame(),null);
            removeStationButton.addActionListener(removeStationListener);
        }
        return removeStationButton;
    }

    private SearchPane getSearchPane() {
        if (searchPane == null) {
            searchPane = new SearchPane(infPane);
        }
        return searchPane;
    }
    private InformationPane infPane;
    private NameMap nameMap;
    private MetroStation station;
    private RemoveStationActionListener removeStationListener;
    private JButton addStationButton;
    private JButton removeStationButton;
    private SearchPane searchPane;
}
